home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 051-075 / scopedisk55 / dirk2 / main.c < prev    next >
C/C++ Source or Header  |  1995-03-18  |  4KB  |  124 lines

  1.  
  2. /***************************************************************************
  3.     1/89
  4.  
  5.         DIRK v2.0 -- Tune workbench colors to system performance
  6.  
  7.         Copyright (C) 1989 by Daniel Elbaum
  8.  
  9.         This software is freely redistributable provided that:
  10.         the four files which comprise it (dirk, dirk.doc, dirk.h,
  11.         adjust.c, main.c, sys, window.c) remain intact; all
  12.         copyright notices contained in any of the aforementioned
  13.         files remain intact; and no fee beyond reasonable remuneration
  14.         for collation and distribution be charged for use and/or
  15.         distribution.
  16.  
  17. ***************************************************************************/
  18.  
  19. #define MAIN
  20. #include "dirk.h"
  21. #define ODD_BEHAVIOR
  22.  
  23. main(c, v)
  24. char **v;
  25. {
  26.     register i, active;
  27.     register ULONG tm;
  28.     register wtog;
  29.     ULONG Class;
  30.     USHORT Code;
  31.     struct Screen *sp;
  32.     struct Window *wp;
  33.     register struct IntuiMessage *msg=NULL;
  34.     t_gf g_f;
  35.     struct Window *getwin();
  36.     ULONG totmem();
  37.     void redowin(), setcolors(), fillwin();
  38.  
  39.     if (getargs(++v, &g_f)<0) exit(10);
  40.  
  41.     if (!(IntuitionBase=(t_ib *)OpenLibrary(INAM, IREV))){
  42.         printf("Couldn't open intuition library\n");
  43.         exit(99);
  44.     }
  45.     if (!(GfxBase=(t_gb *)OpenLibrary(GNAM, GREV))){
  46.         printf("Couldn't open graphics library\n");
  47.         CloseLibrary(IntuitionBase);
  48.         exit(98);
  49.     }
  50.     if (!(sp=IntuitionBase->FirstScreen)){
  51.         printf("Couldn't find any screens\n");
  52.         CloseLibrary(IntuitionBase);
  53.         CloseLibrary(GfxBase);
  54.         exit(97);
  55.     }
  56.     for (; sp; sp=sp->NextScreen)
  57.         if ((sp->Flags&SCREENTYPE)==WBENCHSCREEN)
  58.             break;
  59.     if (!sp) {
  60.         printf("Couldn't find Workbench screen\n");
  61.         CloseLibrary(IntuitionBase);
  62.         CloseLibrary(GfxBase);
  63.         exit(96);
  64.     }
  65.     msg=NULL;
  66.     wtog=W_CLOSED;
  67.     active=0;   /* ACTIVATE not requested by getwin()   */
  68.     if (!(wp=getwin(sp))){
  69.         printf("Couldn't open Dirk's window\n");
  70.         CloseLibrary(IntuitionBase);
  71.         CloseLibrary(GfxBase);
  72.         exit(95);
  73.     }
  74.     if (g_f.bstog) tm=totmem();
  75.     for (;;) {
  76.         while (wp&&(msg||(msg=GetMsg(wp->UserPort)))){
  77.             Class=msg->Class;
  78.             Code=msg->Code;
  79.             ReplyMsg(msg);
  80.             msg=NULL;
  81.             switch(Class){      /* assume sizeof(int)==sizeof(ULONG)    */
  82.                 case ACTIVEWINDOW:
  83.                     active=1;
  84.                     break;
  85.                 case INACTIVEWINDOW:
  86.                     active=0;
  87.                     break;
  88.                 case MOUSEBUTTONS:
  89.                     if ((Code&0xFFFF)==MENUDOWN){
  90.                         redowin(wp, wtog);
  91.                         if (wtog==W_CLOSED) {fillwin(wp); wtog=W_OPEN;}
  92.                         else wtog=W_CLOSED;
  93.                     }
  94.                     break;
  95.                 case CLOSEWINDOW:
  96.                     if (wp){
  97.                         while (msg=GetMsg(wp->UserPort))
  98.                             ReplyMsg(msg);
  99.                         CloseWindow(wp);
  100.                         wp=NULL;
  101.                     }
  102.                     break;
  103.             }
  104.         }
  105.         if (!wp) {
  106.             CloseLibrary(IntuitionBase);
  107.             CloseLibrary(GfxBase);
  108.             exit(0);
  109.         }
  110.         if (active)
  111.             WaitTOF();
  112.         else{
  113.             for (i=0; i<g_f.intvl; ++i)
  114.                 if (msg=GetMsg(wp->UserPort)) break;
  115.                 else WaitTOF();
  116.         }
  117.         if (wtog==W_OPEN) fillwin(wp);
  118.         setcolor(sp, tm, &g_f);
  119.     }
  120.     /* NOTREACHED   */
  121. }
  122.  
  123.  
  124.